﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class CTHoa : System.Web.UI.Page
{
    Hoa h = new Hoa();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        string mahoa = (string)Session["Mahoa"];
        FormCTHoa.DataSource = h.Load_CTHoa(mahoa);
        FormCTHoa.DataBind();

        
        string Maloai=  Session["Maloai"].ToString();
            DTLHoaCungLoai.DataSource = h.Load_HoaCungLoai( Maloai);
            DTLHoaCungLoai.DataBind();

    }
    DataTable tbl = new DataTable();
    protected void DTLHoaCungLoai_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            FormCTHoa.DataSource = h.Load_CTHoa(Mahoa);
            FormCTHoa.DataBind();
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)e.Item.FindControl("lbltenhoa");
            Label gia = (Label)e.Item.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FormCTHoa_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FormCTHoa.FindControl("lbltenhoa");
            Label gia = (Label)FormCTHoa.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
}
